'use strict'
/**
 *
 *
 */

import React from 'react';
import styles from './styles.css';
import { Table } from 'antd';

class AntdTable extends React.Component {

    constructor(props) {
        super(props);
        let size = "default";
        if(props.size === undefined)
            size = "default";
        else{
            switch(props.size){
                case "default":
                    size = "default";
                    break;
                case "small":
                    size = "small";
                    break;
                default:
                    size = "default";
                    break;
            }
        }
        this.state = {
            dataSource: props.dataSource,
            columns: props.columns,
            pagination: props.pagination,
            size: size
        }
    }

    componentWillReceiveProps(props) {
        let size = "default";
        if(props.size === undefined)
            size = "default";
        else{
            switch(props.size){
                case "default":
                    size = "default";
                    break;
                case "small":
                    size = "small";
                    break;
                default:
                    size = "default";
                    break;
            }
        }
        this.setState({
            dataSource: props.dataSource,
            columns: props.columns,
            pagination: props.pagination,
            size: size
        });
    }
    onRowClick(record,index){
        this.props.onRowClick(record,index);
        
    }
    render(){
        //console.log("render table",this.state);
        if(this.state.dataSource){
            //console.log("table",this.state);
            return (
                <Table dataSource={this.state.dataSource} columns={this.state.columns} pagination={this.state.pagination} size={this.state.size} onRowClick={this.onRowClick.bind(this)} />
            );
        }
        else {
            return (
                <span></span>
            )
        }
    }
}

export default AntdTable;
